using APP.HELPER.Data.Helper;
using System;
using System.Data;

namespace Service
{
    internal class License
    {
        private int _mIdLicense;
        private int _mIdSoft;
        private string _mKeyCode;
        private string _mMachineCode;
        private bool _mActive;
        private string _mVersion;
        private DateTime _mDateActive;
        private int _mReActive;
        public bool Active
        {
            get
            {
                return this._mActive;
            }
            set
            {
                this._mActive = value;
            }
        }
        public DateTime DateActive
        {
            get
            {
                return this._mDateActive;
            }
            set
            {
                this._mDateActive = value;
            }
        }
        public License()
        {
            this._mIdLicense = 0;
            this._mIdSoft = 0;
            this._mKeyCode = "";
            this._mMachineCode = "";
            this._mActive = true;
            this._mVersion = "";
            this._mDateActive = DateTime.Now;
            this._mReActive = 0;
        }
        public string Get(string keyCode, string machineCode)
        {
            string result = "";
            object[] parameterValues = new object[]
			{
				keyCode,
				machineCode
			};
            SqlHelper sqlHelper = new SqlHelper("tOPIxxYos7q7KFheUFh/Zczhu/5hC5PryXFA1850bvhMqXE3+8cmhNLR18eIZqCc+X31s2MsNck=", "07071983", true);
            result = "OK";
            //SqlHelper sqlHelper = new SqlHelper("HPqrGX/piQz0Xe4u/h/67gQ3uyF/l8Jnvceflfn0g5a097J0Dujgoj8bqG7F7buoYB2Mt+NKyXJ77rNdpJJ69tNga+CVb/KOMzARhvb5JWkXymCWnUJWzzgLCgblpEMy", "07071983", true);
            //SqlDataReader sqlDataReader = SqlHelper.ExecuteReader(sqlHelper.ConnectionString, "LICENSE_GetMachKeyCode", parameterValues);
            //if (sqlDataReader != null)
            //{
            //    while (sqlDataReader.Read())
            //    {
            //        this._mIdLicense = Convert.ToInt32(sqlDataReader["Id_License"]);
            //        this._mKeyCode = Convert.ToString(sqlDataReader["KeyCode"]);
            //        this._mMachineCode = Convert.ToString(sqlDataReader["MachineCode"]);
            //        this._mActive = Convert.ToBoolean(sqlDataReader["Active"]);
            //        this._mVersion = Convert.ToString(sqlDataReader["Version"]);
            //        this._mDateActive = Convert.ToDateTime(sqlDataReader["DateActive"]);
            //        this._mReActive = Convert.ToInt32(sqlDataReader["ReActive"]);
            //        result = "OK";
            //    }
            //    sqlDataReader.Close();
            //    sqlDataReader.Dispose();
            //    sqlHelper.Close();
            //}
            return result;
        }
        public string Insert(string nameSoft, string keyCode, string machineCode, bool Active, string version)
        {
            string[] myParams = new string[]
			{
				"@NameSoft",
				"@KeyCode",
				"@MachineCode",
				"@Active",
				"@Version"
			};
            object[] myValues = new object[]
			{
				nameSoft,
				keyCode,
				machineCode,
				Active,
				version
			};
            SqlHelper sqlHelper = new SqlHelper("HPqrGX/piQz0Xe4u/h/67gQ3uyF/l8Jnvceflfn0g5a097J0Dujgoj8bqG7F7buoYB2Mt+NKyXJ77rNdpJJ69tNga+CVb/KOMzARhvb5JWkXymCWnUJWzzgLCgblpEMy", "07071983", true);

            return (sqlHelper.ExecuteNonQuery(sqlHelper.Connection, CommandType.StoredProcedure, "LICENSE_InsertName", myParams, myValues).Length > 0) ? "OK" : "NOTOK";
        }
        public string Update(string keyCode, string machineCode)
        {
            string[] myParams = new string[]
			{
				"@KeyCode",
				"@MachineCode"
			};
            object[] myValues = new object[]
			{
				keyCode,
				machineCode
			};
            SqlHelper sqlHelper = new SqlHelper("HPqrGX/piQz0Xe4u/h/67gQ3uyF/l8Jnvceflfn0g5a097J0Dujgoj8bqG7F7buoYB2Mt+NKyXJ77rNdpJJ69tNga+CVb/KOMzARhvb5JWkXymCWnUJWzzgLCgblpEMy", "07071983", true);
            return (sqlHelper.ExecuteNonQuery(sqlHelper.Connection, CommandType.StoredProcedure, "LICENSE_UpdateReActive", myParams, myValues).Length > 0) ? "OK" : "NOTOK";
        }
    }
}